package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhangyu
 * @data 2023/4/24 9:01
 */
@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api(tags = "用户添加购物车相关接口")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    @ApiOperation("用户添加购物车接口")
    public Result<String> addShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shoppingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("用户查看购物车接口")
    public Result<List<ShoppingCart>> selectShoppingCart() {
        return Result.success(shoppingCartService.selectShoppingCart());
    }

    @PostMapping("/sub")
    @ApiOperation("删除购物车单个商品")
    public Result<String> deleteOne(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shoppingCartService.deleteOne(shoppingCartDTO);
        return Result.success();
    }

    @DeleteMapping("/clean")
    @ApiOperation("清空购物车接口")
    public Result<String> cleanShoppingCart() {
        shoppingCartService.cleanShoppingCart();
        return Result.success();
    }


}
